package com.jiefeng.manage.web.controller;

import com.jiefeng.manager.queryRequest.OrderInfoRequest;
import com.jiefeng.manager.service.PayService;
import com.jiefeng.manager.table.OrderInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by huangtongshuan on 2016/6/24 16:49.
 * 订单控制器
 */
@Controller
public class PayOrderInfoCtrl {

    private final Logger logger = LoggerFactory.getLogger(PayOrderInfoCtrl.class);

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private PayService payService;


    /*
    *首页
    */
    @RequestMapping(value = "/index")
    public String index(){
        return "index";
    }

    /**
    * 订单列表页面
    * */
    @RequestMapping(value = "/pay/list")
    public String list(@ModelAttribute("pageParam") OrderInfoRequest orderInfoRequest) {
        //分页
        int pageStartNum = 0;
        //分页计算
        pageStartNum = (orderInfoRequest.getPageNum() - 1) * orderInfoRequest.getPageSize();
        String page = " limit " + String.valueOf(pageStartNum) + "," + String.valueOf(orderInfoRequest.getPageSize());
        orderInfoRequest.setPage(page);
        try {
            List<OrderInfo> orderList = payService.getListBypage(orderInfoRequest);
            orderInfoRequest.setTotalCount(payService.getCount(orderInfoRequest));
            request.setAttribute("pageParam", orderInfoRequest);
            request.setAttribute("orderList", orderList);
        } catch (Exception exception) {
            logger.error("|list|查询订单列表出错|",exception);
        }
        return "/jiefeng/pay/payOrder";
    }

    /**
    * ajax
    * 按照退款订单id查询查询
    * */
    @RequestMapping("/queryOrderDetail/{orderId}")
    public String query(@PathVariable("orderId") String orderId) {
        OrderInfo orderInfo = payService.getOrderListById(orderId);
        request.setAttribute("orderInfo", orderInfo);
        return "/jiefeng/pay/orderDetail";
    }

}
